package com.example.demo.service.impl;

import com.example.demo.context.BaseContext;
import com.example.demo.mapper.TreeHolesMapper;
import com.example.demo.pojo.entity.TreeHoles;
import com.example.demo.pojo.entity.TreeHolesComment;
import com.example.demo.service.TreeHolesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class TreeHolesServiceImpl implements TreeHolesService {
    @Autowired
    private TreeHolesMapper treeHolesMapper;

    @Override
    public List<TreeHoles> list(String content) {
        return treeHolesMapper.list(content);
    }

    @Override
    public void add(String content) {
        TreeHoles treeHoles = new TreeHoles();
        Long userId= BaseContext.getCurrentId();
        treeHoles.setContent(content);
        treeHoles.setUserId(userId);
        treeHoles.setCreateTime(LocalDateTime.now());
        treeHoles.setComment(0);

        treeHolesMapper.insert(treeHoles);
    }

    @Override
    public List<TreeHolesComment> getAllComment(Long id) {
        List<TreeHolesComment> treeHolesComments=treeHolesMapper.getAllCommentByTreeHolesId(id);
        return treeHolesComments;
    }
}
